import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'
import Login from "../views/Login";
import feiyongguanli from "../components/caiwu/feiyongguanli";
import shoufei from "../components/guahao/shoufei";
import tuifei from "../components/guahao/tuifei";
import tuiyao from "../components/yaofang/tuiyao";
import tuihao from "../components/guahao/tuihao";
import xianchangguahao from "../components/guahao/xianchangguahao";
import Changshuleibieguanli from "../components/xitong/Changshuleibieguanli";
import Scheduling from "../components/xitong/Scheduling";
import fayao from "../components/yaofang/fayao";
import huanzhejiancha from "../components/yiji/huanzhejiancha";
import huanzhejianyan from "../components/yiji/huanzhejianyan";
import menzhenbingli from "../components/yisheng/menzhenbingli";
import yijimuban from "../components/yisheng/yijimuban";

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'Login',
    component: Login,
    hidden:true
  },
  {
    path: '/home',
    name: 'Home',
    component: Home,
    hidden:true
  },
  {
    path: '/home',
    name: 'Home',
    component: Home,
    hidden:false,
    meta:{
      title:'挂号收费'
    },
    children:[
      {
        path: '/shoufei',
        name: 'shoufei',
        component: shoufei,
        meta:{
          title:'收费'
        }
      },
      {
        path: '/tuifei',
        name: 'tuifei',
        component: tuifei,
        meta:{
          title:'退费'
        }
      },
      {
        path: '/tuihao',
        name: 'tuihao',
        component: tuihao,
        meta:{
          title:'退号'
        }
      },
      {
        path: '/xianchangguahao',
        name: 'xianchangguahao',
        component: xianchangguahao,
        meta:{
          title:'现场挂号'
        }
      }
    ]
  },
  {
    path: '/home',
    name: 'Home',
    component: Home,
    hidden:false,
    meta:{
      title:'门诊医生'
    },
    children:[
      {
        path: '/menzhenbingli',
        name: 'menzhenbingli',
        component: menzhenbingli,
        meta:{
          title:'门诊病历'
        }
      },
      {
        path: '/yijimuban',
        name: 'yijimuban',
        component: yijimuban,
        meta:{
          title:'医技模板'
        }
      }
    ]
  },
  {
    path: '/home',
    name: 'Home',
    component: Home,
    hidden:false,
    meta:{
      title:'医技处置'
    },
    children:[
      {
        path: '/huanzhejiancha',
        name: 'huanzhejiancha',
        component: huanzhejiancha,
        meta:{
          title:'患者检查'
        }
      },
      {
        path: '/huanzhejianyan',
        name: 'huanzhejianyan',
        component: huanzhejianyan,
        meta:{
          title:'患者检验'
        }
      }
    ]
  },
  {
    path: '/home',
    name: 'Home',
    component: Home,
    hidden:false,
    meta:{
      title:'药房管理'
    },
    children:[
      {
        path: '/fayao',
        name: 'fayao',
        component: fayao,
        meta:{
          title:'发药管理'
        }
      },
      {
        path: '/tuiyao',
        name: 'tuiyao',
        component: tuiyao,
        meta:{
          title:'退药管理'
        }
      }
    ]
  },
  {
    path: '/home',
    name: 'Home',
    component: Home,
    hidden:false,
    meta:{
      title:'财务管理'
    },
    children:[
      {
        path: '/feiyongguanli',
        name: 'feiyongguanli',
        component: feiyongguanli,
        meta:{
          title:'费用管理'
        }
      }
    ]
  },
  {
    path: '/home',
    name: 'Home',
    component: Home,
    hidden:false,
    meta:{
      title:'系统管理'
    },
    children:[
      {
        path: '/Changshuleibieguanli',
        name: 'Changshuleibieguanli',
        component: Changshuleibieguanli,
        meta:{
          title:'常数管理'
        }
      },
      {
        path: '/Scheduling',
        name: 'Scheduling',
        component: Scheduling,
        meta:{
          title:'医生排班管理'
        }
      }
    ]
  }
]

const router = new VueRouter({
  routes
})

import Router from 'vue-router'
const originalPush = Router.prototype.push;
Router.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err);
}

import {Message} from "element-ui";

router.beforeEach((to,from,next)=>{
  if(to.path=='/'){
    next();
  }else{
    let user = window.sessionStorage.getItem('loginUser');
    if(user != null){
      next();
    }else{
      Message.warning({message:'请先登录！'});
      next('/');
    }
  }
})

export default router